import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { DelegateTaskData } from "./DelegateTaskData";
import { DelegateTaskStatus } from "../DelegateTaskStatus";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { DelegateConfig } from "../../../resource/DelegateConfig";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
//class DelegateListRenderer
    
    export  class DelegateListRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.initStyle();
            this.initUI();
            return;
        }

        protected initStyle(): void
        {
            var loc1=GlobalClass.getBitmap("equipment_over");
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        protected initUI(): void
        {
            this._name = ObjCreate.createGTextField("", 0, 10, 150, 20, this, new GTextFormat(FontUtil.defaultName, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            ObjCreate.createBg(0, 50, 150, 2, this, ImagesConst.SplitLine);
            this._process = ObjCreate.createGTextField("", 0, 28, 150, 20, null, new GTextFormat(FontUtil.defaultName, 12, 16776960, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._endBmp = new Object /* flash.display.Bitmap */();
            this._endBmp.x = 50;
            this._endBmp.y = 28;
            LoaderHelp.addResCallBack(ResFileConst.daily, this.onDailyResLoadedHandler);
            return;
        }

        /* internal  */onDailyResLoadedHandler(): void
        {
            this._endBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DailyComIcon);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            super.data = arg1;
            if (typeof data === "delegatetaskdata") 
            {
                loc1 = data as DelegateTaskData;
                loc2 = "#FFFF00";
                if (loc1.status != DelegateTaskStatus.CanDelegate) 
                {
                    if (loc1.status != DelegateTaskStatus.Complete) 
                    {
                        if (loc1.status != DelegateTaskStatus.Delegating) 
                        {
                            if (loc1.status == DelegateTaskStatus.UnReach || loc1.status == DelegateTaskStatus.CanNotDelegate) 
                            {
                                loc2 = "#C688C9";
                                this.addProcess(HTMLUtil.addColor(Language.getString(69854), "#C688C9"));
                                this.removeEndBitmap();
                            }
                        }
                        else 
                        {
                            loc2 = "#00FE31";
                            this.addProcess(HTMLUtil.addColor(Language.getString(69638), "#FF0000"));
                            this.removeEndBitmap();
                        }
                    }
                    else 
                    {
                        loc2 = "#8D8D8B";
                        this.removeProcess();
                        this.addEndBitmap();
                    }
                }
                else 
                {
                    loc2 = "#00FE31";
                    this.removeProcess();
                    this.removeEndBitmap();
                    if (loc1.isDefenceCopy() || loc1.isCrossDefenceCopy()) 
                    {
                        this.addProcess(HTMLUtil.addColor(Language.getString(69711), "#FFFF00"));
                    }
                }
                if (loc1.copy) 
                {
                    this._name.htmlText = HTMLUtil.addColor(loc1.copy.name, loc2);
                }
                else 
                {
                    this._name.htmlText = HTMLUtil.addColor(DelegateConfig.instance.getDelegateName(loc1.tdelegate), loc2);
                }
            }
            return;
        }

        /* internal  */addProcess(arg1: string): void
        {
            if (!this._process.parent) 
            {
                this.addChild(this._process);
            }
            this._process.htmlText = arg1;
            return;
        }

        /* internal  */removeProcess(): void
        {
            if (this._process.parent) 
            {
                this._process.parent.removeChild(this._process);
            }
            return;
        }

        /* internal  */addEndBitmap(): void
        {
            if (!this._endBmp.parent) 
            {
                this.addChild(this._endBmp);
            }
            return;
        }

        /* internal  */removeEndBitmap(): void
        {
            if (this._endBmp.parent) 
            {
                this._endBmp.parent.removeChild(this._endBmp);
            }
            return;
        }

        /* internal */ /* var */_name: GTextFiled;

        /* internal */ /* var */_process: GTextFiled;

        /* internal */ /* var */_endBmp: Object /* flash.display.Bitmap */;
    }
